package screen 
{
	import flash.display.BitmapData;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Matrix;
	/**
	 * ...
	 * @author Zachary Foley
	 */
	public class ScrollingLayer extends Sprite
	{
		protected var bitmapResource:Class;
		protected var scrollingBitmap:BitmapData;
		protected var _parallaxAmount:Number = 1;
		protected var _scaleAmount:Number = 1;
		protected var graphPaperBmp:BitmapData;
		protected var canvas:Graphics;
		protected var matrix:Matrix;
		protected var _startY:int;
		protected var _layerHeight:int;
		
		public function set startY(value:int):void 
		{
			_startY = value;
		}
		public function get startY():int 
		{
			return _startY;
		}
		public function set layerHeight(value:int):void 
		{
			_layerHeight = value;
		}
		public function get layerHeight():int 
		{
			return _layerHeight;
		}
		
		public function ScrollingLayer()
		{
 
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
 
		protected function init(e:Event):void
		{
			matrix = this.transform.matrix.clone();
			removeEventListener(Event.ADDED_TO_STAGE, init);
			canvas = this.graphics;
			matrix.scale(_scaleAmount, _scaleAmount);
			drawCanvas();
			stage.addEventListener(Event.RESIZE, handleResize);
		}
 
		protected function handleResize(e:Event):void
		{
			drawCanvas();
		}
 
		public function move(dx:Number):void {
			matrix.translate(dx * _parallaxAmount, 0);
			//trace(matrix.tx);
			//if (matrix.tx < 0) {
			//	matrix.tx =0//matrix.tx = (scrollingBitmap.width*_scaleAmount)+matrix.tx;
			//}
			//if (matrix.tx > (scrollingBitmap.width*_scaleAmount)) {
			//	matrix.tx = scrollingBitmap.width*_scaleAmount//matrix.tx - (scrollingBitmap.width*_scaleAmount);
			//}
			drawCanvas();
		}
 
		protected function drawCanvas():void
		{
			canvas.clear();
			canvas.beginBitmapFill(scrollingBitmap, matrix, true, false);
			canvas.drawRect(0, 0, 500, 500);
			//canvas.drawRect(0,0,stage.stageWidth, layerHeight);
		}
 
		public function get dx():Number { return matrix.tx; }
 
		public function set dx(value:Number):void
		{
			matrix.tx = value * _parallaxAmount;
			drawCanvas();
		}
 
		public function get parallaxAmount():Number { return _parallaxAmount; }
 
		public function set parallaxAmount(value:Number):void
		{
			_parallaxAmount = value;
		}

		public function get scaleAmount():Number { return _scaleAmount; }
 
		public function set scaleAmount(value:Number):void
		{
			_scaleAmount = value;
			
		}
		
	}
 
}